//
//  MenuTabBar.m
//  GWT
//
//  Created by cnmobi on 15/4/13.
//  Copyright (c) 2015年 cnmobi. All rights reserved.
//

#import "MenuTabBar.h"
#import "ViewRoomViewController.h"
#import "OrdersViewController.h"
#import "RecordViewController.h"
#import "SettingViewController.h"


#define Dev_IOSVersion [[[UIDevice currentDevice] systemVersion] floatValue]

@interface MenuTabBar ()

@property (nonatomic,strong)UINavigationController *recordNavCtl;

@end

@implementation MenuTabBar

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.tabBar.backgroundImage = [UIImage imageWithColor:RGB(248, 248, 248, 1) size:CGSizeMake(20, 49)];
    
    self.tabBar.selectionIndicatorImage = [UIImage imageWithColor:RGB(248, 248, 248, 1) size:CGSizeMake(20, 49)];
    

   
    OrdersViewController *communityViewctl = [[OrdersViewController alloc]init];
    UIImage *serviceImage = [[UIImage imageNamed:@"tabbar1_nor"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *serviceselectImage = [[UIImage imageNamed:@"tabbar1_high"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    communityViewctl.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"接单" image:serviceImage selectedImage:serviceselectImage];
    communityViewctl.tabBarItem.tag = 0;
    //    communityViewctl.tabBarItem.imageInsets = UIEdgeInsetsMake(4, 0, -4, 0);
    UINavigationController *communityNavCtl = [[UINavigationController alloc] initWithRootViewController:communityViewctl];
    
    ViewRoomViewController *homeViewCtl =  [[ViewRoomViewController alloc]init];
    UIImage *mainImage = [[UIImage imageNamed:@"tabbar2_nor"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *mainselectImage = [[UIImage imageNamed:@"tabbar2_high"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    homeViewCtl.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"看房" image:mainImage selectedImage:mainselectImage];
    homeViewCtl.tabBarItem.tag = 1;
    //    homeViewCtl.tabBarItem.imageInsets = UIEdgeInsetsMake(4, 0, -4, 0);
    UINavigationController *homeNavCtl = [[UINavigationController alloc] initWithRootViewController:homeViewCtl];
    
    
    RecordViewController *recordViewctl = [[RecordViewController alloc]init];
    UIImage *signImage = [[UIImage imageNamed:@"tabbar3_nor"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *signselectImage = [[UIImage imageNamed:@"tabbar3_high"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    recordViewctl.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"接单记录" image:signImage selectedImage:signselectImage];
    recordViewctl.tabBarItem.tag = 2;
//    setViewctl.tabBarItem.imageInsets = UIEdgeInsetsMake(4, 0, -4, 0);
    _recordNavCtl = [[UINavigationController alloc] initWithRootViewController:recordViewctl];
    
    SettingViewController *setViewctl = [[SettingViewController alloc]init];
    UIImage *setImage = [[UIImage imageNamed:@"tabbar4_nor"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *setselectImage = [[UIImage imageNamed:@"tabbar4_high"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    setViewctl.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"设置" image:setImage selectedImage:setselectImage];
    setViewctl.tabBarItem.tag = 3;
    //    setViewctl.tabBarItem.imageInsets = UIEdgeInsetsMake(4, 0, -4, 0);
    UINavigationController *setNavCtl = [[UINavigationController alloc] initWithRootViewController:setViewctl];
    
    

    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:FontSize(10), NSForegroundColorAttributeName:[UIColor lightGrayColor]} forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:FontSize(10), NSForegroundColorAttributeName:RGB(51 ,133 ,255, 1)} forState:UIControlStateHighlighted];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:FontSize(10), NSForegroundColorAttributeName:RGB(51 ,133 ,255, 1)} forState:UIControlStateSelected];
    //tabBar背景颜色
    //设置强制背景不透明
    //  self.tabBar.translucent = NO;
    
    
    NSArray *viewCtlArr = [NSArray arrayWithObjects:communityNavCtl,homeNavCtl,_recordNavCtl,setNavCtl, nil];
    
    self.viewControllers = viewCtlArr;
    self.selectedIndex = 0;

    self.delegate = self;
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(recordPushController:) name:RecordPushVC object:nil];

}

#pragma mark - noti
-(void)recordPushController:(NSNotification *)noti
{
    self.selectedIndex = 2;
    
    UIViewController *vc = noti.object;
    HideTabbar(vc);
    [_recordNavCtl pushViewController:vc animated:YES];
    
}

@end
